﻿using DriverLicence.Cnsl.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace DriverLicence.Cnsl.ViewRender
{
    internal class ProgramUserInteraction
    {
        internal static void RenderWelcome()
        {
            /*
            var assembly = Assembly.GetEntryAssembly();
            assembly.GetCustomAttribute(Type.)
             */

        }

        internal static void RenderTitle(string quizTitle)
        {
            Console.Clear();
            RenderNewSection();
            Console.WriteLine("Welcome to the {0}", quizTitle);
            RenderNewSection();
            Console.WriteLine("Press any key to start our quiz...");
            Console.ReadKey();
        }

        internal static int GetCantQuestions(int top)
        {
            int result;
            string userSelection;
            Console.Clear();
            do
            {
                Console.WriteLine("How many questions do you want? (between 0 and {0})", top);
                userSelection = Console.ReadLine();
                Console.WriteLine("***Invalid option***");
                Console.WriteLine();
            } while (!int.TryParse(userSelection, out result) || result <= 0 || result > top);
            Console.Clear();
            return result;
        }

        internal static int GetOptionIndex(string statement, IAnswer[] options)
        {
            Console.Clear();
            Console.WriteLine(statement);
            RenderNewSection();
            int i, j;
            int cantOptions = options.Length;
            string response;
            for (i = 0; i < cantOptions; i++)
            {
                Console.WriteLine("{0} - {1}", i + 1, options[i].Value);
            }
            do
            {
                RenderNewSection();
                Console.Write("Your option is: ");
                response = Console.ReadLine();
            } while (!int.TryParse(response, out j) || j <= 0 || j > cantOptions);
            return j - 1;
        }

        internal static void RenderOptionResult(string optionMessage)
        {
            RenderNewSection();
            Console.WriteLine(optionMessage);
            RenderNewSection();
            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }

        internal static void RenderResult(float accertionPercentage)
        {
            Console.Clear();
            RenderNewSection();
            Console.WriteLine("Your result is: {0}%", accertionPercentage);
            RenderNewSection();
            Console.WriteLine("The end...");
            Console.ReadKey();
        }

        private static void RenderNewSection()
        {
            Console.WriteLine("-----------------");
            Console.WriteLine();
        }
    }
}
